package main

import (
	"fmt"
	"time"
)

func main() {
	//创建一个有缓存channel
	ch := make(chan int, 3)
	fmt.Printf("len(ch) = %d,cap(ch) = %d\n", len(ch), cap(ch))
	go func() {
		for i := 0; i < 10; i++ {

			ch <- i //往chan 写内容
			fmt.Printf("子协程: i = %d\n", i)
			fmt.Printf("len(ch) = %d,cap(ch) = %d\n", len(ch), cap(ch))
		}
	}()

	//延迟
	time.Sleep(2 * time.Second)
	for i := 0; i < 10; i++ {
		num := <-ch //读管道中内容，没有内容前，阻塞
		fmt.Println("num = ", num)
	}
}
